package com.encryption.controls.loading
{
	import mx.core.FlexGlobals;
	import mx.core.UIComponent;
	import mx.managers.PopUpManager;

	/**
	 * 弹出延迟等待提示工具
	 * @author yudw
	 * 
	 */	
	public class DelayPopUpManager
	{
		//存放调用函数传递过来的父类容器
		private static var map:Object = {};
		
		public function DelayPopUpManager()
		{
			trace("Class DelayPopUpManager was loaded");
		}
		
		/**
		 *在指定的父容器中弹出延迟等待小提示 
		 * @param label 需要提示的具体信息
		 * @param parent 提示框的父类容器
		 * 
		 */		
		public static function popUp(label:String,parent:UIComponent=null):void
		{
			if(parent == null)
				parent = FlexGlobals.topLevelApplication as UIComponent;
			var key:String = parent.toString();
			if(map.hasOwnProperty(key) && map[key] != null)
				return;
			
			var delayComponent:LoadingComponent = new LoadingComponent();
			map[key] = delayComponent;
			//修改提示信息
			delayComponent.message = label;
			//在指定的父类容器中显示，其他窗口可以被点击
			PopUpManager.addPopUp(delayComponent,parent,true);
			//居中显示
			PopUpManager.centerPopUp(delayComponent);
		}
		/**
		 * 从指定父容器中删除提示框
		 * @param parent 提示框的父类容器
		 * 
		 */		
		public static function removePop(parent:UIComponent):void
		{
			var key:String = parent.toString();
			if(map.hasOwnProperty(key)){
				var delayComponent:LoadingComponent=map[key];
				delete map[key];
				if(delayComponent!=null)
				{
					PopUpManager.removePopUp(delayComponent);
					delayComponent=null;
				}
			}
		}
		
		/**
		 *移除所有的提示框信息 
		 * 
		 */		
		public static function removeAllTips():void
		{
			if(map==null)
			{
				return;
			}
			else{
				for (var key:String in map)
				{
					var delayComponent:LoadingComponent=map[key];
					if(delayComponent!=null)
					{
						delete map[key];
						PopUpManager.removePopUp(delayComponent);
						delayComponent=null;
					}else
					{
						return;
					}
				}
			}
		}
		
	}
}